function [ masb ] = readbinkw( t, datadir )
    % converting time into vector (see MatLab help for details)
    tt = datevec(t);
    % directory with '.bin' files [with '\']
    directory=datadir;
    
    % generating file name using datevec
    year=int2str(tt(1));
    mounth=int2str(tt(2));
    if length(mounth)<2
        mounth(2)=mounth(1);
        mounth(1)='0';
    end
    day=int2str(tt(3));
    if length(day)<2
        day(2)=day(1);
        day(1)='0';
    end
    % 'tofile' - file location
    tofile='';

    tofile(1:length(directory))=directory;
    tofile(length(directory)+1:length(directory)+17)='kw********.bg.bin';
    tofile(length(directory)+3:length(directory)+6)=year;
    tofile(length(directory)+7:length(directory)+8)=mounth;
    tofile(length(directory)+9:length(directory)+10)=day;

    % open file
    fid = fopen(tofile,'r');
    B = fread(fid);

    % create output massive
    masb=zeros(length(B)/20-1,9);

    % dealing with binary data %)
 
    % old code
%     for i=0:length(B)/20-1
%         masb(i+1,1)=B(20*i+1)*16777216+B(20*i+2)*65536+B(20*i+3)*256+B(20*i+4);
%         masb(i+1,2)=B(20*i+5)*256+B(20*i+6);
%         masb(i+1,3)=B(20*i+7)*256+B(20*i+8);
%         masb(i+1,4)=B(20*i+9)*256+B(20*i+10);
%         masb(i+1,5)=B(20*i+11)*256+B(20*i+12);
%         masb(i+1,6)=B(20*i+13)*256+B(20*i+14);
%         masb(i+1,7)=B(20*i+15)*256+B(20*i+16);
%         masb(i+1,8)=B(20*i+17)*256+B(20*i+18);
%         masb(i+1,9)=B(20*i+19)*256+B(20*i+20);
%     end
    
    % vectorized code (much faster)
    i=0:length(B)/20-1;
        masb(i+1,1)=B(20*i+1)*16777216+B(20*i+2)*65536+B(20*i+3)*256+B(20*i+4);        
        masb(i+1,2)=B(20*i+5)*256+B(20*i+6);
        masb(i+1,3)=B(20*i+7)*256+B(20*i+8);
        masb(i+1,4)=B(20*i+9)*256+B(20*i+10);
        masb(i+1,5)=B(20*i+11)*256+B(20*i+12);
        masb(i+1,6)=B(20*i+13)*256+B(20*i+14);
        masb(i+1,7)=B(20*i+15)*256+B(20*i+16);
        masb(i+1,8)=B(20*i+17)*256+B(20*i+18);
        masb(i+1,9)=B(20*i+19)*256+B(20*i+20);

    % 1st row - time in ms
    % 2nd and 6th rows - G1
    % 3rd and 7th rows - G2
    % 4th and 8th rows - G3
    % 5th and 9th rows - G4

end

